package hibernate.modelConverter;

import hibernate.model.Aygit;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("AygitConverter")
public class AygitConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
			System.out.println("3");
			//AygitBean agtBean = (AygitBean) fc.getExternalContext().getSessionMap().get("AygitBean");
			if(!value.equals("")){
				System.out.println("value ="+ value);
				Aygit agt = new Aygit();
				agt.setAygitid((Long.parseLong(value.trim())));
				System.out.println("malibu : "+agt.getAygitTuru());
				return agt;
			}
						
			System.out.println("4");
			return null; // **** alternative with return null; ****
		
	}
	
	@Override
	public String getAsString(FacesContext fc, UIComponent uic, Object value) {
		if (value == null || value.equals("")) {
			System.out.println("1");
			return "";
		} else {
			Aygit agt = (Aygit) value;
			System.out.println("2 ve id " + agt.getAygitid());
			System.out.println("2 ve tur " + agt.getAygitTuru());
			return ""+agt.getAygitid();
		}
	}
}